package gang.org.springframework.framework.util;

import sun.swing.StringUIClientPropertyKey;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

/**
 * @author gang.chen
 * @description
 * @Date 2021/8/4 12:47
 */
public abstract class GangResourceUtils {
    public static final String CLASSPATH_URL_PREFIX="classpath*:";

    public static File getFile(URL resourceUrl, String description){

        if (false){
            //TODO
        }

        return new File(toURI(resourceUrl).getSchemeSpecificPart());
    }

    public static URI toURI(URL url){
        return toURI(url.toString());
    }

    //before location="file:/D:/2022/source/gang-springboot/gang-springboot/target/classes/gang/com/org/service/"
    //after  location="file:/D:/2022/source/gang-springboot/gang-springboot/target/classes/gang/com/org/service/"
    public static URI toURI(String location){
        try {
            return new URI(GangStringUtils.replace(location, " ", "%20"));
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }
}
